/**
 * Created by BlueCat on 2020/06/03 15:18.
 */
export function stringify (obj, prefix) {
  const pairs = []
  for (const key in obj) {
    if (!Object.prototype.hasOwnProperty.call(obj, key)) {
      continue
    }
    const value = obj[key]
    const enkey = encodeURIComponent(key)
    let pair
    if (value !== undefined) {
      if (typeof value === 'object') {
        pair = stringify(value, prefix ? prefix + '[' + enkey + ']' : enkey)
      } else {
        pair = (prefix ? prefix + '[' + enkey + ']' : enkey) + '=' + encodeURIComponent(value)
      }
      pairs.push(pair)
    }
  }
  return pairs.join('&')
}

// 获取真实有效的href
export function getRealHref () {
  const { origin, pathname, hash } = window.location
  return origin + pathname + hash
}
export function randomString (len = 32) {
  // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
  const str = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  const length = str.length
  let pwd = ''
  for (let i = 0; i < len; i++) {
    pwd += str.charAt(Math.floor(Math.random() * length))
  }
  return pwd
}
